#pragma once

#include "SkinDef.h"
#include "SkinableGUIImage.h"

namespace SkinableGUI
{
	class CSkinManager
	{
	public:
		CSkinManager(void);
		virtual ~CSkinManager(void);

	public:
		BOOL InitializeSkin(const CString & skinFolder);
		void ReleaseSkin();

		BOOL LoadXmlSkinFile(const CString & xmlPath,
			SkinWindow & skinWindow);

		BOOL UpdateWindowStyle(CWnd * pWnd, const SkinWindowStyle & windowStyle);
		BOOL UpdateControlStyle(CWnd * pWnd, const SkinControlStyle & controlStyle);
		CWnd * CreateControl(CWnd * pParentWnd, const SkinControl & control);

		BOOL LoadFont(const SkinFont & skinFont, CFont & font);
		BOOL LoadImage(const SkinImage & skinImage, CSkinableGUIImage & image);

		const CString & GetSkinPath() { return m_strSkinPath; }
		const CString & GetMediaPath() { return m_strMediaPath; }
		const CString & GetFontPath() { return m_strFontPath; }
		const CString & GetLanguagePath() { return m_strLanguagePath; }
		const CString & GetWindowPath() { return m_strWindowPath; }

		static CSkinManager * GetInstance();
	protected:
		BOOL HandleXmlNode(void * pNode,
			SkinWindow & skinWindow);
		BOOL LoadSkinControl(void * pNode,
			SkinControl & skinControl,
			SkinControl * parentSkinControl);
		BOOL LoadSkinWindowStyle(void * pNode,
			SkinWindowStyle & skinWindowStyle);
		BOOL LoadSkinFont(void * pNode,
			SkinFont & skinFont);
		BOOL LoadSkinRectangle(void * pNode,
			SkinRectangle & skinRectangle);
		BOOL LoadSkinControlStyle(void * pNode,
			SkinControlStyle & skinControlStyle);
		BOOL LoadSkinImage(void * pNode,
			SkinImage & skinImage);
		BOOL LoadSkinColor(void * pNode,
			SkinColor & skinColor);
		BOOL LoadSkinButton(void * pNode,
			SkinButton & skinButton,
			SkinControl * parentSkinControl);
		BOOL LoadSkinBitmapButton(void * pNode,
			SkinBitmapButton & skinBitmapButton,
			SkinControl * parentSkinControl);
		BOOL LoadSkinPictureControl(void * pNode,
			SkinPictureControl & skinPicture,
			SkinControl * parentSkinControl);
		BOOL LoadSkinListBox(void * pNode,
			SkinListBox & skinListBox,
			SkinControl * parentSkinControl);
		BOOL LoadSkinScrollBar(void * pNode,
			SkinScrollBar & skinScrollBar);
		BOOL LoadSkinScrollBarPos(void * pNode,
			SkinScrollBarPos & skinScrollBarPos);

		CString GetNodeValue(void * pNode, LPCTSTR nodeName);
		void SetDefaultValue(SkinWindow & skinWindow);

	private:
		CString m_strSkinPath;
		CString m_strMediaPath;
		CString m_strLanguagePath;
		CString m_strFontPath;
		CString m_strWindowPath;

		BOOL m_bInitialized;
	};
}

